home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc04.arc / TABDEC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-15  |  1.1 KB  |  64 lines

  1. /* tabdec: tab decoder */
  2.  
  3. #define  MAXLINE  80
  4. #define  YES      1
  5. #define  NO      0
  6. #define  TABSP      8
  7.  
  8. char  input[] "data";
  9. char  ibuf[518];
  10. int   tabs[MAXLINE];
  11.  
  12. main()
  13. {
  14.       int   col, *ptab;
  15.       char  c;
  16.  
  17.       ptab = tabs;
  18.       col = 1;
  19.  
  20.       settab(ptab);  /* set initial tab stops */
  21.       if (fopen(input, ibuf) < 0) {
  22.      printf("%s: not found\n", input);
  23.      exit(8);
  24.       }
  25.       while ((c = getc(ibuf)) != -1) {
  26.      switch (c) {
  27.         case '\t': /* TAB */
  28.            while (tabpos(col) != YES) {
  29.           putchar(' ');  /* put BLANK */
  30.           col++;
  31.            }
  32.            break;
  33.         case '\n':  /* NEWLINE */
  34.            putchar('\n');
  35.            col = 1;
  36.            break;
  37.         default:
  38.            putchar(c);
  39.            col++;
  40.      }
  41.       }
  42. }
  43.  
  44.  
  45. tabpos(col) /*tabpos: return YES if col is a tab stop */
  46. int   col;
  47. {
  48.       if (col > MAXLINE)
  49.      return(YES);
  50.       else
  51.      return(tabs[col]);
  52. }
  53.  
  54.  
  55. settab(tabp)   /* settab: set initial tab stops */
  56. int   *tabp;
  57. {
  58.       int   i;
  59.  
  60.       for (i = 0; i <= MAXLINE; i++)
  61.      (i % TABSP) ? (tabs[i] = NO) : (tabs[i] = YES);
  62. {
  63.  
  64.